package chat

import (
	"gxcvu-ai/app/model"
	"gxcvu-ai/pkg/database"
)

type Message struct {
	model.BaseModal

	UserID  uint   `json:"user_id,omitempty"`
	ChatID  uint   `json:"chat_id,omitempty"`
	Role    string `json:"role,omitempty"`
	Content string `json:"content,omitempty"`

	model.CommonTimestampsField
}

func GetAllMsg(uid string) (data []Message) {
	database.DB.Where("user_id = ?", uid).Find(&data)
	return
}

func GetMsg(uid string, chat_id uint) (data []Message) {
	database.DB.Where("user_id = ? and chat_id = ?", uid, chat_id).Limit(4).Find(&data)
	return
}

func CreateMsg(data Message) bool {
	return database.DB.Create(&data).Error == nil
}
